import {Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation} from '@angular/core';
import {ActivatedRoute, Params} from "@angular/router";
import {Observable} from "rxjs";

import {Content} from "@shared/components/toolbar/toolbar-content";
import {HomepageService} from "@homepage/homepage.service";
import {ToolsService} from "@shared/service/tools/tools.service";
import {ToolbarService} from "@shared/components/toolbar/toolbar.service";
import {EventsService} from "@core/events/events.service";
import {UserAlbumFileVO} from "@interface/index";



@Component({
  selector: 'seed-my-video',
  templateUrl: 'my-video.component.html',
  styleUrls: ['my-video.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class MyVideoComponent implements OnInit, OnDestroy {
  public src: string;
  public poster: string;
  public videoThumbnail: Observable<UserAlbumFileVO[]>;
  @ViewChild(Content) content;
  @ViewChild('modal') modal;

  constructor(public homepageService: HomepageService,
              public toolsService: ToolsService,
              public _activatedRoute: ActivatedRoute,
              public toolBarService: ToolbarService,
              private events: EventsService) {
    this.videoThumbnail = this.homepageService.videoThumbnail;
  }

  showVideoView(src: string) {
    if (!src) {
      return;
    }
    this.src = src;
    /*this.poster = src+'&width=300&second=1';*/
    this.poster = this.toolsService.replaceVideoUrl(src, 300);
    this.modal.show();
  }


  ngOnInit() {
    this._activatedRoute.queryParams.do(() => this.toolBarService.unfoldNav()).subscribe(param => {
      if (param['userId']) {
        this.homepageService.getUserAlbum(param['userId'], 3, 1, 1, 20);
      }
    });
  }

  ngOnDestroy() {
    this.events.unsubscribe('on-popup');
    this.toolsService.hideLoading();
  }

}
